<?php
namespace app\kucun\model;

use think\Model;

class ProductStockLogModel extends Model{

    protected $table = 'kucun_product_stock_log';
    protected $pk = 'id';


    CONST STOCK_OPTION_IN_SHOP = 1; //  正常在店
    CONST STOCK_OPTION_OUT_SHOP = 2; // 从店铺出库
    CONST STOCK_OPTION_SELE = 3; // 已销售

    protected $datetime_format = "m-d H:i";

    CONST STOCK_OPTION_ARR = [
        1 => "入库",
        2 => "出库",
        3 => "销售",
    ];

    protected $append = ['option_str'];

    public function shop(){
        return $this->hasOne(ShopModel::class,'id','option_shop_id');
    }

    public function user(){
        return $this->hasOne(WxWorkUserModel::class,'id','option_uid');
    }

    public function getOptionStrAttr(){
        return self::STOCK_OPTION_ARR[$this->option_id] ?? '';
    }

}